package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.response.Result;
import jakarta.annotation.Resource;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("consumer")
public class OrderController {

    private static final String PaymentSrv_URL = "http://cloud-payment-service";

    @Resource
    private RestTemplate restTemplate;

    @GetMapping("pay/add")
    public Result addPay(@RequestBody PayDTO payDTO){
        return restTemplate.postForObject(PaymentSrv_URL+"/pay/add",payDTO,Result.class);
    }

    @GetMapping("pay/get/{id}")
    public Result getPay(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(PaymentSrv_URL+"/pay/get/"+id,Result.class);
    }

    @GetMapping("pay/update")
    public Result<String> updatePay(@RequestBody PayDTO payDTO){
        restTemplate.put(PaymentSrv_URL+"/pay/update",payDTO);
        return Result.success("更新成功");
    }

    @GetMapping("pay/delete/{id}")
    public Result<String> deletePay(@PathVariable("id") Integer id){
        System.out.println("ss");
        restTemplate.delete(PaymentSrv_URL+"/pay/delete/"+id);
        return Result.success("删除成功");
    }

    @GetMapping("test")
    public String test(){
        return restTemplate.getForObject(PaymentSrv_URL+"/test",String.class);
    }
}
